/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session01;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sinhnx <sinhnx@fpt.aptech.ac.vn>
 */
public class ResultSetInfo {
    public static void main(String[] args) {
        String url = "jdbc:sqlserver://192.168.1.51:1433;databaseName=APJII_DB;user=sinhnx;password=fat123456";
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

            Connection cn = DriverManager.getConnection(url);

            Statement stm = cn.createStatement();

            ResultSet rs = stm.executeQuery("SELECT * FROM Subjects");

            ResultSetMetaData rsmd = rs.getMetaData();
            
            for(int i=1; i<=rsmd.getColumnCount(); i++){
                System.out.println(rsmd.getColumnName(i) + " " + rsmd.getColumnTypeName(i));
            }
            
            rs.close();
            stm.close();
            cn.close();
        } catch (SQLException ex) {
            Logger.getLogger(JDBC_ODBC.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(JDBC_ODBC.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
